package com.jy.adscm.operation.mscyb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.JqbzSettingsDraws;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqbzSettingsDrawsMapper;
import com.jy.adscm.operation.mscyb.service.JqbzSettingsDrawsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.zltx.bean.JyDrawingList;
import com.jy.adscm.zltx.bean.JyDrawingRole;
import com.jy.adscm.zltx.bean.JyDrawingType;
import com.jy.adscm.zltx.bean.SjFile;
import com.jy.adscm.zltx.mapper.mysql.JyDrawingListMapper;
import com.jy.adscm.zltx.mapper.mysql.JyDrawingRoleMapper;
import com.jy.adscm.zltx.mapper.mysql.JyDrawingTypeMapper;
import com.jy.adscm.zltx.service.JyDrawingListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-05-20
 */
@Service
public class JqbzSettingsDrawsServiceImpl extends ServiceImpl<JqbzSettingsDrawsMapper, JqbzSettingsDraws> implements JqbzSettingsDrawsService {
    @Autowired
    JyDrawingListService jyDrawingListService;
    @Autowired
    JyDrawingRoleMapper jyDrawingRoleMapper;
    @Autowired
    JyDrawingListMapper jyDrawingListMapper;
    @Autowired
    JyDrawingTypeMapper jyDrawingTypeMapper;
    @Override
    public List<JqbzSettingsDraws> selectJqbzSettingsDrawsByPid(String pid) throws AdscmSystemException {
        Wrapper<JqbzSettingsDraws> wrapper =new EntityWrapper<>();
        wrapper.eq("pid",pid);
        List<JqbzSettingsDraws> jqbzSettingsDraws = super.selectList(wrapper);
        for (JqbzSettingsDraws jqbzSettingsDraw : jqbzSettingsDraws) {
            JyDrawingList jyDrawingList = jyDrawingListMapper.selectById(jqbzSettingsDraw.getCid());
            if (AdscmBaseUtils.getInstance().isNotEmpty(jyDrawingList,null)){
                jqbzSettingsDraw.setCidName(jyDrawingList.getDrawingName());
            }
        }
        return jqbzSettingsDraws;
    }

    @Override
    public List<JyDrawingList> selectAll(Integer parentId, Integer id) throws AdscmSystemException {
        Wrapper<JyDrawingList> wrapper=new EntityWrapper<>();
        wrapper.eq("parent_id",parentId);
        wrapper.eq("drawing_type",id);
        List<JyDrawingList> jyDrawingLists = jyDrawingListMapper.selectList(wrapper);
        return jyDrawingLists;
    }

    @Override
    public List<JyDrawingList> selectByKeyWord(String keyword) {
        Wrapper<JyDrawingList> wrapper =new EntityWrapper<>();
        wrapper.like("drawing_name",keyword);
        wrapper.andNew();
        wrapper.eq("drawing_type","1");
        wrapper.or();
        wrapper.eq("drawing_type","2");
        wrapper.or();
        wrapper.eq("drawing_type","3");
        wrapper.setSqlSelect("id","drawing_name","drawing_type");
        List<JyDrawingList> jyDrawingLists = jyDrawingListMapper.selectList(wrapper);
        for (JyDrawingList jyDrawingList : jyDrawingLists) {
            JyDrawingType jyDrawingType = jyDrawingTypeMapper.selectById(jyDrawingList.getDrawingType());
            jyDrawingList.setDrawingTypeName(jyDrawingType.getName());
        }
        return jyDrawingLists;
    }
}
